package cn.iocoder.yudao.module.indicator.base;

import cn.iocoder.yudao.module.indicator.service.element.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @Description 元素查询工厂类
 *
 * @Author ZWC
 * @Date 2024/9/26 16:32
 */
@Component
public class ElementCalculationFactory {

    private final ElementCalculationService elementDayService;
    private final ElementCalculationService elementDoctorService;
    private final ElementCalculationService elementRoomService;
    private final ElementCalculationService elementDataMonthXkService;

    // 使用构造函数注入依赖
    @Autowired
    public ElementCalculationFactory(ElementDayServiceImpl elementDayService,
                                     ElementDoctorServiceImpl elementDoctorService,
                                     ElementRoomServiceImpl elementRoomService,
                                     ElementMonthXkServiceImpl elementMonthXkService) {
        this.elementDayService = elementDayService;
        this.elementDoctorService = elementDoctorService;
        this.elementRoomService = elementRoomService;
        this.elementDataMonthXkService = elementMonthXkService;
    }

    private enum ServiceType{
        DAY("ELEMENT_DATA_DAY"), DOCTOR("ELEMENT_DATA_DOCTOR_DAY"),ROOM("ELEMENT_DATA_ROOM_DAY"),
        XKFZ("ELEMENT_DATA_XK");
        private final String code;
        ServiceType(String code) {
            this.code = code;
        }
        public static ServiceType fromCode(String code) {
            return Arrays.stream(values())
                    .filter(c -> c.code.equals(code))
                    .findFirst()
                    .orElseThrow(() -> new IllegalArgumentException("Invalid code: " + code));
        }
    }
    public ElementCalculationService getElementService(String type) {
        if (StringUtils.isNotEmpty(type)) {
            ServiceType serviceType = ServiceType.fromCode(type.toUpperCase());
            switch (serviceType) {
                case DAY:
                    return elementDayService;
                case DOCTOR:
                    return elementDoctorService;
                case ROOM:
                    return elementRoomService;
                case XKFZ:
                    return elementDataMonthXkService;
                default:
                    throw new IllegalArgumentException("指标维度配置越界：" + type);
            }
        }
        throw new IllegalArgumentException("未明确指标维度！");
    }
}
